<?php

/**
 * Modul pro hromadnou aktualizaci.
 *
 * @author David Dusek
 */
class UpdaterModule extends CMS\AbstractModule {    
    public function hookAdminMenu() {
        return array("title" => "adminMenuTitle",
                     "link" => ":Updater:Template:default",
                     "img" => "btn_update.png");
    }
    
    public function hookAdminSubmenu() {
        $submenu = array(
            0 => array(
                "title" => "listTemplate",
                "link" => ":Updater:Template:default",
                "icon" => "ui-icon-clipboard",
                "right" => "list"
            ),
            1 => array (
                "title" => "addTemplate",
                "link" => ":Updater:Template:add",
                "icon" => "ui-icon-plus",
                "right" => "add"
            ),
            2 => array (
                "title" => "listDomain",
                "link" => ":Updater:Domain:default",
                "icon" => "ui-icon-clipboard",
                "right" => "list"
            ),
            3 => array (
                "title" => "addDomain",
                "link" => ":Updater:Domain:add",
                "icon" => "ui-icon-plus",
                "right" => "add"
            )
        );
        return $submenu;
    }
    
    public function hookUserGetAcl() {
        $acl = array(
            "Template" => array(
                "name" => "updater_aclTemplateTitle",
                "operations" => array(
                    "list" => "updater_aclList", 
                    "add" => "updater_aclAdd", 
                    "edit" => "updater_aclEdit", 
                    "delete" => "updater_aclDelete"
                ),
            ),
            "Domain" => array(
                "name" => "updater_aclDomainTitle",
                "operations" => array(
                    "list" => "updater_aclList", 
                    "add" => "updater_aclAdd", 
                    "edit" => "updater_aclEdit", 
                    "delete" => "updater_aclDelete",
                ),
            ),
        );
        
        return $acl;
    }
    
    /**
     * Zasifrovani parametru funkce volane pomoci RPC.
     * @param array $params Pole parametru.
     * @param string $key Sdileny klic.
     * @return string 
     */
    public static function encode($params, $key) {        
        $string = implode(',', $params);
        $encoded = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));
        return $encoded;
    }
}
